package com.sky.controller.user;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.IShoppingCartService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-23
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户端-购物车相关接口")
public class ShoppingCartController {
    private final IShoppingCartService shoppingCartService;
    @PostMapping("/add")
    public Result<String> add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        return shoppingCartService.add(shoppingCartDTO);
    }
    @GetMapping("list")
    public Result<List<ShoppingCart>> list() {
        LambdaQueryWrapper<ShoppingCart> wrapper=new LambdaQueryWrapper<ShoppingCart>()
                .eq(ShoppingCart::getUserId, BaseContext.getCurrentId());
        return Result.success(shoppingCartService.list(wrapper));
    }

    @DeleteMapping("/clean")
    public Result<String> clean() {
        shoppingCartService.remove(null);
        return Result.success();
    }

}
